local joyex__jizhi = fk.CreateSkill {

  name = "joyex__jizhi",

  tags = {  },

}



joyex__jizhi:addEffect(fk.CardUsing, {
  name = "joyex__jizhi",
  anim_type = "drawcard",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(joyex__jizhi.name) and data.card.type == Card.TypeTrick
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:getCardById(player:drawCards(1)[1])
    if card.type == Card.TypeBasic and player.phase == Player.Play then
      room:addPlayerMark(player, MarkEnum.AddMaxCardsInTurn, 1)
    elseif card.type == Card.TypeEquip and room:getCardOwner(card) == player and room:getCardArea(card) == Player.Hand then
      local targets = table.map(table.filter(room:getOtherPlayers(player), function(p)
        return p:hasEmptyEquipSlot(card.sub_type) end), function(p) return p.id end)
      if #targets == 0 then return end
      local to = room:askForChoosePlayers(player, targets, 1, 1, "#joyex__jizhi-choose:::"..card:toLogString(), joyex__jizhi.name, true)
      if #to > 0 then
        room:moveCards({
          ids = {card:getEffectiveId()},
          from = player.id,
          to = to[1],
          toArea = Card.PlayerEquip,
          moveReason = fk.ReasonPut,
          proposer = player.id,
          skillName = joyex__jizhi.name,
        })
      end
    elseif card.type == Card.TypeTrick and player.phase == Player.Play then
      room:addPlayerMark(player, "joyex__jizhi-phase", 1)
    end
  end,
})

joyex__jizhi:addEffect("targetmod", {
  name = "#joyex__jizhi_targetmod",
  --joyex__jizhi,
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("joyex__jizhi-phase") > 0 and scope == Player.HistoryPhase then
      return player:getMark("joyex__jizhi-phase")
    end
    return 0
  end,
})

return joyex__jizhi